<?php
namespace app\controller\v1;

use think\facade\View;

use app\controller\v1\Base;
use app\model\Industry as IndustryModel;

class Industry extends Base
{
    public function index() 
    {
        $list = IndustryModel::field('id, title, titlepic, summary, create_time')->paginate(12);

        View::assign('list', $list);

        return View::fetch();
    }

    public function read($id = 0)
    {
        if ($id == 0) {
            return $this->notFound('文章不存在');
        }

        $data = IndustryModel::getOne($id);

        if ($data == null) {
            return $this->notFound("文章不存在");
        }

        if ($data->type==1) {
            View::config(['view_path' => $this->app->getRootPath().'view/']);

            return View::display($data->content);
        } else {
            $nextprev = IndustryModel::getNextPrev($id);

            // 覆盖Base seo
            $this->system['title'] = $data->title . '-' . $this->system['title'];
            $this->system['key'] = $data->key . '-,' . $this->system['key'];
            $this->system['des'] = $data->des;

            View::assign('system', $this->system); 

            return View::fetch('', [
                'data'     => $data,
                'nextprev' => $nextprev
            ]);
        }
    }
}
